#!/bin/sh
exec 1> "${1:-/dev/stdout}"
cat << EOF
const char *XEventName(int type) {
	switch(type) {
EOF
DIR="$(pkg-config x11 --variable=includedir)/X11"
if [ -f "$DIR/X.h" ]; then
	gawk '
		/Event names\./,/must be bigger than any event/ {
			if ($1 == "#define") {
				printf "\tcase %2d: return \"%s\";\n", $3, $2
			}
		}' "$DIR/X.h"
fi

cat << EOF
	default: return "UnknownEvent";
	}
}
EOF
